package com.dzpk.gameserver.util;

import somnus.cache.CacheKey;
import somnus.cache.CacheModel;
import somnus.cache.ICache;
import somnus.pool.ThreadPoolManager;

/**
 * 异步获取缓存信息
 * 
 * @author Somnus
 * 
 */

public class AsyncGetCache {

    private ICache cache;

    private ThreadPoolManager threadPoolManager;

    public void get(final CacheKey key, final AsyncGetCallback callback) {

        threadPoolManager.execute(new Runnable() {

            @Override
            public void run() {
                CacheModel data = cache.get(key);
                if (callback != null) {
                    callback.gotData(data);
                }
            }
        });

    }

    public void setCache(ICache cache) {
        this.cache = cache;
    }

    public void setThreadPoolManager(ThreadPoolManager threadPoolManager) {
        this.threadPoolManager = threadPoolManager;
    }

    public interface AsyncGetCallback {

        public void gotData(CacheModel obj);
    }
}
